<?
function array_shuffle ($array) {
    while (count($array) > 0) {
        $val = array_rand($array);
        $new_arr[$val] = $array[$val];
        unset($array[$val]);
    }
    return $new_arr;
}
function lacunas_shuffle ($ls) {
	$lacunas = array();
	foreach($ls as $l) {
	    $lacunas[] = $l;
	}
	return array_shuffle($lacunas);
}
?>
<script type="text/javascript"
	src="<?=$this->publicUrl?>/scripts/jquery.ui-1.0/ui.mouse.js"></script>
<script type="text/javascript"
	src="<?=$this->publicUrl?>/scripts/jquery.ui-1.0/ui.core.js"></script>
<script type="text/javascript"
	src="<?=$this->publicUrl?>/scripts/jquery.ui-1.0/ui.draggable.js"></script>
<script type="text/javascript"
	src="<?=$this->publicUrl?>/scripts/jquery.ui-1.0/ui.droppable.js"></script>



<script type="text/javascript">
$(document).ready(function () {

	  executou = false;
	  acertou = 1;
	  erro = "";
	  valor = "";
 
  $('.testar_lacuna').click(function () {
    var t = this; 
    var lacuna = document.getElementById("lacuna["+t.id+"]");
      
          $.ajax({
          url: '<?=$this->baseUrl?>/textos/validar',
          data: 'usuario='+<?=$this->usuario?>+'&valor='+ lacuna.value+'&id=' + t.id,
          dataType: 'json',
          type: 'post',
          cache: false,
          async: false,
          success: function (j) {
            window.alert(j.msg);
          }
        });
      
      
      this.lastValue = this.value;
   
  });

  $('.confirmar').click(function() {
	  erro = "";
	  var lacunas = $('.divDrop');
	  for(var i = 0; i < lacunas.size(); i++) {
		lacuna_value = unescape(lacunas[i].innerHTML);
		lacuna_id = lacunas[i].id;
		
		$.ajax({
	          url: '<?=$this->baseUrl?>/textos/validarassoc',
	          data: 'usuario='+<?=$this->usuario?>+'&valor='+ lacuna_value+'&id=' + lacuna_id,
	          dataType: 'json',
	          cache: false,
	          async: false,
	          type: 'post',
	          success: function (j) {
	            if (j.acertou == 0) {
					erro = j.id_lacuna;
					valor = j.lacuna;
		        }
	          }
	     });	
	  }
	  if (erro == "") {
		alert("Parabens! Voce acertou!");
	  } else {
		alert("Oopps! Voce errou!");	
	 }
  });
   
});


</script>
<style>
.divDrop {
	width: 150px !important;
	height: 20px;
	margin-right: 4px;
	background-color: powderBlue;
	font-size: 14px;
	padding: 2px 50px 2px 50px;
}

.lacuna_assoc {
	padding-right: 5px;
}

.thickbox {
	position: relative;
	top: 4px;
	margin-right: 5px;
}

br {
	clear: left;
}

a{
	padding:10px;
}
p{
	clear:left;
}

#lacunas {
	width: 320px;
	float: left;
	margin-bottom: 8px;
}

#lacunas div {
	float: left;
	margin: 3px;
}

#galeria{
	width: 1200px !important;
	backgroud: #0000FF;
}

#galeria .galeria_cadastro{
	width: 130px;
	background: #F4F4F4;
	text-align: center;
	padding:5px;
	margin:5px;
	float:left;
}

.divDrag {
	cursor: move;
	border: 1px outset #c0c0c0;
	font-size: 14px;
	padding: 2px 10px;
	text-align: center;
	background-color: yellow;
	z-index: 999;
	float: left;
}

.droppable-active {
	opacity: 1.0;
	background-color: yellow;
}

.droppable-hover {
	outline: 1px dotted black;
	background-color: white;
}
</style>

<script type="text/javascript">

$(document).ready

(

function() {

$(".divDrag").draggable(
{
helper: 'clone',
opacity:  5
}


);

$(".divDrop").droppable({

accept: ".divDrag",


activeClass: 'droppable-active',

hoverClass: 'droppable-hover',

tolerance: 'touch',

drop: function(ev, ob) {


     var dropguy = $(ob.draggable);
     var drop_id = dropguy.attr("id");
     var drop_value = dropguy.text();
   
      
     $(this).html(drop_value);

}


});

 

}); 
</script>



<ul id="barra_navegacao">
	<?if($this->perfil != 'professor'): ?>
		<li><a href="<?=$this->baseUrl ?>/textos/">Pesquisar Textos</a> &gt;</li>
	<?else:?>
		<li><a href="<?=$this->baseUrl ?>/admintextos/">Admin Textos</a> &gt;</li>
	<?endif; ?>
	<li><?=$this->texto->titulo ?></li>
</ul>
<div id="<?=$this->textClass?>">
<h2><?=$this->texto->titulo ?></h2>
<h4>
    Publicado por: <?=$this->texto->findParentUsuarios()->nome?>, em <?=$this->texto->data ?></h4>
	
	<?foreach($this->imgs as $this->resul_imagens ){?>
	<? /* <a href="http://www.criarsite.net.br" target="_blank">outra janela</a> */?>
	<div id="galeria">
	<div class= "galeria_cadastro">
	<a href="<?=$this->baseUrl?>/<?if ($this->resul_imagens->nome_imagem): ?><?=@$this->resul_imagens->nome_imagem?><?else: ?><? endif;?>" target="_blank"><span><img src="<?=$this->baseUrl?>/<?if ($this->resul_imagens->nome_imagem): ?><?=@$this->resul_imagens->nome_imagem?><?endif;?>" width="120" height="90" title ="clique para vizualizar melhor a imagem"alt= "imagem" /></span></a>
	</div>
	</div>
	<? 
	
	
	}
	 ?>
	
	
<p>
    <?=$this->texto_completo ?>

    </p>
<? if ($this->lacunas_associacao && $this->perfil != 'visitante'):  ?>
<input type="button" class="confirmar" value="Confirmar" /></div>
<? endif; ?>

<? $salvar = false; ?>
<? if ($this->boxLateral) : ?>
<div id="questionario">
<div id="area_fixa">
<? if ($this->lacunas_associacao):  ?>
<h2>Associe estas lacunas ao texto:</h2>
<div id="lacunas">    
<? $lacunas = lacunas_shuffle ($this->lacunas); ?>
<? foreach($lacunas as $lacuna) : ?>
<div class='divDrag' id="<?=$lacuna->id?>"><?=utf8_encode($lacuna->palavra)?></div> 
<? endforeach; ?>
</div>
<? endif; ?> 
<? if (count($this->perguntas)) :?>
<h2>Perguntas acerca do texto:</h2>
<form method="post"
	action="<?=$this->baseUrl ?>/questionarios/responder"><input
	type="hidden" name="idTexto" value="<?=$this->texto->id ?>" />
<? foreach($this->perguntas as $i => $pergunta): ?>
<fieldset>

<p><?=$i+1?>) <?=$pergunta->pergunta ?></p>
<? /* ?>
<input type="radio" name="p1" value="a" id="p1_a" /><label for="p1_a">O
mosquito da Dengue</label> <input type="radio" name="p1" value="a"
	id="p1_b" /><label for="p1_b">Os pol�ticos curruptos</label> <input
	type="radio" name="p1" value="a" id="p1_c" /><label for="p1_c">A
viol�ncia nas cidades</label> <input type="radio" name="p1" value="a"
	id="p1_d" /><label for="p1_d">As guerras no oriente m�dio</label>
*/ ?>
<? 
$resposta = $pergunta->findRespostasByPerguntas(); 
if (count($resposta)): 
$resposta = $resposta->current();
$correcoes = $resposta->findCorrecoesByRespostas();
?>
	<p><?= $resposta->resposta ?>
	<? if (count($correcoes)): ?>
		<strong>(<a
	href="<?=$this->baseUrl?>/questionarios/correcao/resposta/<?=$resposta->id?>">visualizar
corre&ccedil;&atilde;o</a>)</strong>
	<? endif; ?>
	</p> 
<? else:  ?>
<textarea name="respostas[<?=$pergunta->id?>]" id="<?=$pergunta->id?>"></textarea>
<? 
$salvar = true;
endif; ?>
</fieldset>
<? endforeach; ?>
<? if ($salvar): ?>
<input type="submit" value="salvar"/></form>
<? endif; ?>
<? endif; ?>
</div>
</div>
<? endif; ?>
</div>

